local cuige = fk.CreateSkill{
  name = "rainveil__cuige",
}

Fk:loadTranslationTable{
  ["rainveil__cuige"] = "摧戈",
  [":rainveil__cuige"] = "出牌阶段每种手牌数限一次，你可以将手牌数调整至3，然后本阶段视为未使用过牌。",
  ["@rainveil__cuige-turn"] = "摧戈",

  ["$rainveil__cuige1"] = "蜀营连绵百里，正待吾燎原一炬！",
  ["$rainveil__cuige2"] = "蜀军虚实已知，吾等不日便破也！",
}

cuige:addEffect("active", {
  can_use = function (self, player)
    return not table.contains(player:getTableMark("@rainveil__cuige-turn"), player:getHandcardNum()) and player:getHandcardNum() ~= 3
  end,
  card_filter = function (self, player, to_select, selected, selected_targets)
    if player:getHandcardNum() < 3 then return end
    return table.contains(player:getCardIds(Player.Hand), to_select) and #selected < player:getHandcardNum() - 3
  end,
  target_filter = function (self, player, to_select, selected, selected_targets)
    return false
  end,
  feasible = function (self, player, selected, selected_cards, card)
    return player:getHandcardNum() < 3 or #selected_cards == player:getHandcardNum() - 3
  end,
  on_use = function (self, room, effect)
    local player = effect.from
    room:addTableMark(player, "@rainveil__cuige-turn", player:getHandcardNum())
    if player:getHandcardNum() < 3 then
      player:drawCards(3 - player:getHandcardNum(), cuige.name)
    else
      room:throwCard(effect.cards, cuige.name, player)
    end
    player:setCardUseHistory("", 0, Player.HistoryPhase)
  end
})

return cuige